package com.china.zhuoyue.ui.activity.estate.home.service

import android.view.View
import com.china.zhuoyue.R
import com.china.zhuoyue.databinding.ActivityScoreBinding
import com.china.zhuoyue.databinding.ItemImpressionTagBinding
import com.china.zhuoyue.ui.base.BaseActivity
import com.china.zhuoyue.ui.base.BaseRecyclerAdapter
import com.china.zhuoyue.ui.base.BaseViewHolder
import com.china.zhuoyue.ui.ext.toastMessageLong
import com.china.zhuoyue.ui.utils.FullyGridLayoutManager
import com.china.zhuoyue.ui.widget.CommonButton
import java.text.DecimalFormat

class ScoreActivity : BaseActivity<ActivityScoreBinding>() {
    private val mDecimalFormat = DecimalFormat("0.#")
    override fun initView() {
        loadView {
            bindViewClick(vb.buttonSubmit)
            tvRating.text = getString(R.string.text_estate_score_num, mDecimalFormat.format(0f))
            rbRating.setOnRatingBarChangeListener { ratingBar, rating, fromUser ->
                tvRating.text = getString(R.string.text_estate_score_num, mDecimalFormat.format(rating))
            }
            rvTag.adapter = ImpressionTagAdapter().apply {
                datas = ImpressionTagAdapter.TAG
            }
            rvTag.layoutManager = FullyGridLayoutManager(mThis, 3)
        }
    }

    override fun onClick(v: View?) {
        when (v) {
            vb.buttonSubmit -> {
                "提交成功".toastMessageLong()
                finish()
            }
        }
    }
}

class ImpressionTagAdapter : BaseRecyclerAdapter<BaseViewHolder<ItemImpressionTagBinding>, Int>() {
    companion object {
        val TAG = mutableListOf<Int>().apply {
            add(R.string.text_estate_score_impression_tag_1)
            add(R.string.text_estate_score_impression_tag_2)
            add(R.string.text_estate_score_impression_tag_3)
            add(R.string.text_estate_score_impression_tag_4)
            add(R.string.text_estate_score_impression_tag_5)
        }
    }

    override fun onBindViewHolder(holder: BaseViewHolder<ItemImpressionTagBinding>, bean: Int, position: Int) {
        holder.vb.apply {
            cbTag.setText(bean)
            setViewClick(position, cbTag)
        }
    }

    override fun subOnClickAdapter(v: View, position: Int) {
        (v as? CommonButton)?.let {
            if (CommonButton.CB_TAG == it.getCbStyle()) {
                it.changeStyle(CommonButton.CB_NORMAL)
            } else {
                it.changeStyle(CommonButton.CB_TAG)
            }
        }
    }
}